<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>filter过滤元素使用</title>
</head>
<body>
    <script>
        let arr = ['sffd','djskf'];

        // 新数组取所有返回值为true的元素
        let newArr = arr.filter(function (value) {
            return true;
        });
        console.log(newArr);



        let score = [
            {name:"张三",score:99},
            {name:"李四",score:78},
            {name:"王五",score:55},
        ];

        let hightScore = score.filter(function (value) {
            return value.score >= 60;
        })

        console.table(hightScore);



        // filter方法的实现原理
        let array = [1,2,3,4,5];
        function  filters(array,callback) {
            let newArray = [];
            for (const value of array) {
                if(callback(value) == true){
                    newArray.push(value);
                }
            };
            return newArray;
        };
        console.log(filters(array,function (value) {
            return value > 2;
        }));
    </script>
</body>
</html>